"""__slots__ 用来限定类中，只有固定的属性字段，不使用字典保存对象的实例属性"""


class MyClassNoSlots(object):
    def __init__(self, name, identifier):
        self.name = name
        self.identifier = identifier
        # 不使用__slots__,类中的属性，可以进行自定义添加
        # self.personInfo = name + "-->" + identifier

    # def __str__(self) -> str:
    #     return super().__str__()

    def __str__(self):
        print("class info== %s, %s" % (self.name, self.identifier))
        return "MyClassNoSlots: %s, %s" % (self.name, self.identifier)





class MyClassSolts(object):
    __slots__ = ['name', 'identifier']

    def __init__(self, name, identifier):
        self.name = name
        self.identifier = identifier
        # 使用了__slots__，如果使用了__slots__中未定义的是属性，将报错，报错信息如下
        # AttributeError: 'MyClassSolts' object has no attribute 'personInfo'
        # self.personInfo = name + "-->" + identifier


noslots = MyClassNoSlots("Simon", "abcd1234")


solts = MyClassSolts("卡西", "0804209")
# solts.personInfo = solts.name + "---" + solts.identifier
# noslots.add = noslots.personInfo


print(noslots)
print(solts)
